package com.ruoyi.web.controller.module.market;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.market.domain.Wallet;
import com.ruoyi.market.service.IWalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 钱包充值金额配置信息
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/market/wallet")
public class WalletController extends BaseController
{
    @Autowired
    private IWalletService walletService;

    /**
     * 获取钱包充值金额配置列表
     */
    @PostMapping("/walletList")
    public TableDataInfo list(@RequestBody Wallet wallet, HttpServletRequest request)
    {
        String shopId = request.getHeader("ShopId"); // 店铺id
        if(shopId != null && !shopId.equals("")){
            wallet.setShopId(shopId);
        }
        startPageByPost();
        List<Wallet> list = walletService.selectWalletList(wallet);
        return getDataTable(list);
    }

    /**
     * 根据钱包充值金额配置编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('market:wallet:query')")
    @GetMapping(value = { "/", "/{walletId}" })
    public AjaxResult getInfo(@PathVariable(value = "walletId", required = false) Long walletId)
    {
        AjaxResult ajax = AjaxResult.success();
        if (StringUtils.isNotNull(walletId))
        {
            Wallet sysWallet = walletService.selectWalletById(walletId);
            ajax.put(AjaxResult.DATA_TAG, sysWallet);
        }
        return ajax;
    }

    /**
     * 新增钱包充值金额配置
     */
    @PreAuthorize("@ss.hasPermi('market:wallet:add')")
    @Log(title = "钱包充值金额配置管理 - 新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Wallet wallet, HttpServletRequest request)
    {
        String shopId = request.getHeader("ShopId"); // 店铺id
        if(shopId != null && !shopId.equals("")){
            wallet.setShopId(shopId);
        }
        wallet.setCreateBy(getUsername());
        return toAjax(walletService.insertWallet(wallet));
    }

    /**
     * 修改钱包充值金额配置
     */
    @PreAuthorize("@ss.hasPermi('market:wallet:edit')")
    @Log(title = "钱包充值金额配置管理 - 修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Wallet wallet)
    {
        wallet.setUpdateBy(getUsername());
        return toAjax(walletService.updateWallet(wallet));
    }

    /**
     * 删除钱包充值金额配置
     */
    @PreAuthorize("@ss.hasPermi('market:wallet:remove')")
    @Log(title = "钱包充值金额配置管理 - 删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{walletIds}")
    public AjaxResult remove(@PathVariable Long[] walletIds)
    {
        return toAjax(walletService.deleteWalletByIds(walletIds));
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('market:wallet:edit')")
    @Log(title = "钱包充值金额配置管理 - 状态修改", businessType = BusinessType.UPDATE)
    @PutMapping("/walletChangeStatus")
    public AjaxResult changeStatus(@RequestBody Wallet wallet)
    {
        wallet.setUpdateBy(getUsername());
        return toAjax(walletService.updateWalletStatus(wallet));
    }
}
